#include <iostream>
#include "vector"
#include "setjmp.h"
using namespace std;
static jmp_buf buf;
struct EnumAlmostCoro
{
    enum State
    {
        Start,
        Resume,
        Finish
    };

    State cur;
    vector<int> chosen;

    vector<int> tag;

    EnumAlmostCoro() : cur(Start)
    {
        tag = vector<int>(5,0);
    }


    void getNext(int level)
    {
        int i = 1;
//        if (cur == Finish)
//            return false;
        if (cur == Resume)
            goto CoroResume;

        if(chosen.size()==5){
            if(tag[0]&&tag[1] && tag[2]){
                for(int c:chosen){
                    cout << c ;
                }
                cout<< endl;
                longjmp(buf,0);
                CoroResume:;
            }
        }
        for (int i = 0; i < 5; ++i) {
            if (tag[i]==0){
                tag[i] = 1;
                chosen.emplace_back(i);
                getNext(1);
                chosen.pop_back();
                tag[i]=0;
            }
        }
        if(level==0){
            longjmp(buf,1);
        }
    }
};
void printRecursive(vector<int> &tag,vector<int> &chosen){
    if(chosen.size()==5){
        for(int c:chosen){
            cout << c ;
        }
        cout<< endl;
    }
    for (int i = 0; i < 5; ++i) {
        if (tag[i]==0){
            tag[i] = 1;
            chosen.emplace_back(i);
            printRecursive(tag,chosen);
            chosen.pop_back();
            tag[i]=0;
        }
    }
}
int main() {
//    vector<int> chosen;
//    vector<int> tag(5,0);
//    printRecursive(tag, chosen);
    EnumAlmostCoro coro;
    if(!setjmp(buf)){
        coro.getNext(0);
        coro.cur = EnumAlmostCoro::Resume;
    }
}
